#!/usr/bin/env python
import sys, math, random
import src.crop as cr
from mpi4py import MPI
import numpy as np
import operator as op
import util

comm = MPI.COMM_WORLD
p = comm.size
rank = comm.rank
root = 0
data_dir = "../data/"
crop = cr.CRoP(0.1, rank, p)

A = B = np.load('../data/np_mat__10000_0.001.npy',mmap_mode='r')
print "processor %s starting" % rank
if rank == 0 :
    print "nnz ", np.count_nonzero(A)
n = 0
with util.Timer() as t :
	while n < len(A[0]) :
	    crop.crop(A.T[n,:], B[n,:])
	    n += 1
print 'processor  %s finished %.03f sec' % (rank,t.interval)
summary = crop.get_summary(type='list')

data = comm.gather(summary, root)

if rank == root :
	print 'master  %s finished %.03f sec' % (rank,t.interval)
#	for i in range(p) :
#		print data[i]

else :
	assert data is None
sys.exit()